/*
 * @Author: 梁卓
 * @Date: 2022-01-28 21:45:59
 * @LastEditTime: 2022-02-12 21:39:39
 * @LastEditors: Please set LastEditors
 * @Description: vuex
 * @FilePath: \dreamUi\src\store\index.js
 */
import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    // 缓存用户信息
    token: sessionStorage.getItem('token') || '',
    name: sessionStorage.getItem('name') || '',
    avatar: sessionStorage.getItem('avatar') || '',
    roles: [],
    menus: [],
    permissions: [],
  },
  mutations: {
    /**
     *  向vuex中存入token
     * @param {*} state 
     * @param {*} data 
     */
    setToken(state, data) {
      state.token = data;
      sessionStorage.setItem('token',data);
    },
    /**
     * vuex中存入用户姓名
     * @param {*} state 
     * @param {*} data 
     */
    setName(state, data) {
      state.name = data;
    },
    /**
     * vuex中存入头像信息
     * @param {*} state 
     * @param {*} data 
     */
    setAvatar(state, data) {
      state.avatar = data;
    },
    /**
     * vuex中存入角色信息 
     * @param {*} state 
     * @param {*} data 
     */
    setRoles(state, data) {
      state.roles = data;
    },
    /**
     * vuex中存入菜单信息
     * @param {*} state 
     * @param {*} data 
     */
    setMenus(state, data) {
      state.menus = data;
    },
    /**
     * vuex中存入权限数据：限制用户操作
     * @param {*} state 
     * @param {*} data 
     */
    setPermissions(state, data) {
      state.permissions = data;
    }
  },
  actions: {},
  modules: {},
});
